//-----------------------------------------------------------------------------
// Bend2D - Physics Engine
// Roberto Bender <beto.bender@gmail.com>
// Description: 
// Date: 17/05/2010
//-----------------------------------------------------------------------------
#ifndef COLORS_H
#define COLORS_H

namespace bend2d
{
    class Color
    {
        public:
            enum eColorSourceType
            {
                eSourceType8888,
                eSourceType565,
                eSourceTypeYCbCr,
            };

            enum eColorOutputMask
            {
                eOutputMaskRed8888          = 0xFF0000FF,
                eOutputMaskGreen8888        = 0x00FF00FF,
                eOutputMaskBlue8888         = 0x0000FFFF,
                eOutputMaskRedGreen8888     = eOutputMaskRed8888 | eOutputMaskGreen8888,
                eOutputMaskRedBlue8888      = eOutputMaskRed8888 | eOutputMaskBlue8888,
                eOutputMaskGreenBlue8888    = eOutputMaskGreen8888 | eOutputMaskBlue8888,
                eOutputMaskFull8888         = eOutputMaskRed8888 | eOutputMaskGreen8888 | eOutputMaskBlue8888,

                eOutputMaskRed565           = 0xF800,
                eOutputMaskGreen565         = 0x07E0,
                eOutputMaskBlue565          = 0x001F,
                eOutputMaskRedGreen565      = eOutputMaskRed565 | eOutputMaskGreen565,
                eOutputMaskRedBlue565       = eOutputMaskRed565 | eOutputMaskBlue565,
                eOutputMaskGreenBlue565     = eOutputMaskGreen565 | eOutputMaskBlue565,
                eOutputMaskFull565          = eOutputMaskRed565 | eOutputMaskGreen565 | eOutputMaskBlue565,
            };

            enum eColorComponent
            {
                eColorComponentRed,
                eColorComponentGreen,
                eColorComponentBlue,
            };
           
            Color(); 
            Color(unsigned int color, eColorSourceType type = eSourceType8888);
            Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);

            unsigned short To565(eColorOutputMask mask = eOutputMaskFull565) const;
            unsigned int To8888(eColorOutputMask mask = eOutputMaskFull8888) const;

            void ToGLFloat(float& r, float& g, float& b, float& a) const;
            double GetRedFloat() const { return (double) m_Red / 255.0; }
            double GetGreenFloat() const { return (double) m_Green / 255.0; }
            double GetBlueFloat() const { return (double) m_Blue / 255.0; }
            
            unsigned char GetRed() const;
            unsigned char GetBlue() const;
            unsigned char GetGreen() const;
            unsigned char GetAlpha() const;
            


            void SetAlpha(unsigned char alpha);
            bool Match(const Color& color, unsigned char error = 20) const;
            void Normalize();
            void NormalizeColors(unsigned char number = 17);

            bool operator == (const Color& right) const;

            bool IsTheHighestComponent(eColorComponent component) const;

        private:
            unsigned char m_Red;
            unsigned char m_Green;
            unsigned char m_Blue;
            unsigned char m_Alpha;
    };
}

#endif

